package com.personal.website.lottery.web.service.impl;

import com.personal.website.lottery.web.dao.DoubleColorBallMapper;
import com.personal.website.lottery.web.model.DoubleColorBall;
import com.personal.website.lottery.web.model.DoubleColorBallExample;
import com.personal.website.lottery.web.service.DoubleColorBallService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Gavin on 2016/2/15.
 */
@Service("doubleColorBallService")
public class DoubleColorBallServiceImpl implements DoubleColorBallService {
    @Resource
    private DoubleColorBallMapper doubleColorBallMapper;

    public List<DoubleColorBall> getBalls(int num) {
        DoubleColorBallExample doubleColorBallExample = new DoubleColorBallExample();
        doubleColorBallExample.setLimitLength(num);
        doubleColorBallExample.setOrderByClause("draw_date desc");
        return this.doubleColorBallMapper.selectByExample(doubleColorBallExample);
    }

    public DoubleColorBall getLatestBall() {
        return getBalls(1).get(0);
    }

    public List<DoubleColorBall> getDoubleColorBallLikeIssue(int issue, int limit) {
        DoubleColorBallExample example = new DoubleColorBallExample();
        example.setLimitLength(limit);
        example.setOrderByClause("register_time desc");
        DoubleColorBallExample.Criteria criteria = example.createCriteria();
        criteria.andIssueEqualTo(issue);
        return this.doubleColorBallMapper.selectByExample(example);
    }

    public DoubleColorBall getBallById(int doubleColorBallId) {
        return this.doubleColorBallMapper.selectByPrimaryKey(doubleColorBallId);
    }

    public boolean deleteDoubleColorBall(int doubleColorBallId) {
        return this.doubleColorBallMapper.deleteByPrimaryKey(doubleColorBallId) == 1;
    }

    @Override
    public boolean updateDoubleColorBall(DoubleColorBall doubleColorBall) {
        return this.doubleColorBallMapper.updateByPrimaryKey(doubleColorBall) == 1;
    }
}
